/*
 * @Description:分析数据组件
 * @Author: kanglin
 * @Date: 2018-09-05 13:50:01
 * @Copyright: Created by Panxsoft.
 */

<style lang="less" scoped rel="stylesheet/less" type="text/less" >
.v-com-lottie-loading {
  height: 100%;
  width: 100%;
  z-index: 9999;
  position: absolute;
  top: 0;
  left: 0;

  .loading-stage {
    height: 1.8rem;
    width: 2rem;
    border-radius: .2rem;
    background-color: rgba(0, 0, 0, 0.5);
    text-align: center;
    padding-top: 0.2rem;
    position: absolute;
    top: 0; left: 0;right: 0;bottom: 0;
    margin: auto;

    .lottie-loading {
      height: 1.1rem;
      width: 1.1rem;
      margin-left: .45rem;
    }

    .loading-text {
      margin-top: 0.15rem;
      color: white;
    }
  }
}
</style>

<template>
	<div
		v-show="show"
		class="v-com-lottie-loading">
		<div class="loading-stage">
			<div
				ref="lottie-loading"
				class="lottie-loading"/>
			<div class="loading-text">{{ loading_text }}</div>
		</div>
	</div>
</template>

<script>
/**
 * airbnb 的动画库
 */
import lottie from 'lottie-web';
import { mapState } from 'vuex';

export default {
	name: 'LottieLoading',

	computed: {
		// 有命名空间的 vuex
		...mapState('lottieLoading', [
			'show',
		]),
	},

	data() {
	  return {
			loading_text: this.$t('common.wait'),
		};
	},

	mounted() {
		const loading_elm = this.$refs['lottie-loading'];

		lottie.loadAnimation({
			container: loading_elm, // the dom element that will contain the animation
			renderer: 'svg',
			loop: true,
			autoplay: true,
			path: '/assets/wx/lottie/lodingx.json', // public path
		});
	},
};
</script>
